<?php if (Yii::app()->user->hasFlash('success')): ?>

    <div class="alert alert_grey">
        <img height="24" width="24" src="<?php echo Yii::app()->params['backendUrl']; ?>/images/icons/small/grey/success.png">
        <?php echo Yii::app()->user->getFlash('success'); ?>
    </div>
<?php endif; ?>
<?php if (Yii::app()->user->hasFlash('error')): ?>
    <div class="alert alert_grey">
        <img height="24" width="24" src="<?php echo Yii::app()->params['backendUrl']; ?>/images/icons/small/grey/alert_2.png">
        <?php echo Yii::app()->user->getFlash('error'); ?>
    </div>
<?php endif; ?>

<div class="flat_area grid_16">
    <h2>Report Income</h2>
</div>
<?php
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
        $('.search-form').toggle();
        return false;
});
$('.search-form form').submit(function(){
        $.fn.yiiGridView.update('sys-ewallet-withdrawal-grid', {
                data: $(this).serialize()
        });
        return false;
});
");
?>
<div class="search-form">
    <div class="form">
        <div class="box grid_16 round_all">
            <h2 class="box_head grad_colour round_all">Advanced Search</h2>
            <a href="#" class="grabber">&nbsp;</a>
            <a href="#" class="toggle toggle_closed">&nbsp;</a>
            <div class="toggle_container" style="<?php echo (isset($_GET['month'], $_GET['year']) ? '' : 'display:none'); ?>;">
                <?php
                $this->renderPartial('_search');
                ?>
            </div>

        </div>
    </div>
</div>

<?php
/*
  echo '
  <div id="menu-grid" class="grid-view">
  <table width="50%" class="items">
  <thead><tr>
  <th>Jenis Aktivasi</th><th>Jumlah Aktivasi</th><th>Total Pemasukkan (Rp)</th>
  </tr></thead>
  <tbody>
  ';
  if(!empty($results_income)) {
  /*
  echo '<pre>';
  print_r($results_income);
  echo '</pre>'; */
//$nominal=0;
//echo $results_income[0]['Jumlah'];
//echo $results_income[0]['Jumlah'];
/* $grand_total=0;
  foreach($results_income AS $row)
  {
  $jenis=$row['network_level_status_log_value'];
  $nominal=($jenis=='distributor')?100000:(
  ($jenis=='warehouse')?600000:(
  ($jenis=='factory')?6000000:0));
  $total=$nominal*$row['Jumlah'];
  $grand_total+=$total;
  echo '<tr><td>'.$row['network_level_status_log_value'].'</td>';
  echo '<td align="right">'.$row['Jumlah'].'</td>';
  echo '<td align="right">'.number_format($total,0,",",'.').'</td></tr>';
  }
  echo '<tr><td>Grand Total</td><td colspan="2" align="right">'.number_format($grand_total,0,',','.').'</td></tr>';
  }
  else {
  echo '<td colspan="3">Belum ada data</td>';
  }
  echo '
  </tbody>
  </table>
  </div>
  ';
 */

/*
  $this->widget('zii.widgets.grid.CGridView', array(
  'id'=>'sys-network-level-status-log-grid',
  'dataProvider'=>$dataProviderIncome,
  'columns' => array(

  array(
  'header'=>'Jenis Aktivasi',
  'name'=>'network_level_status_log_value',
  'value' => '$data["network_level_status_log_value"]',
  'htmlOptions' => array('style' => 'text-align:center;'),
  ),
  array('header' => 'Jumlah Aktivasi',
  'value' => '$data["Jumlah"]',
  'htmlOptions' => array('style' => 'text-align:center;'),
  ),
  array('header' => 'Total Pemasukkan (Rp)',
  'value' => '
  number_format(($data["network_level_status_log_value"]=="distributor")?100000*$data["Jumlah"]:(
  ($data["network_level_status_log_value"]=="warehouse")?600000*$data["Jumlah"]:(
  ($data["network_level_status_log_value"]=="factory")?6000000*$data["Jumlah"]:0*$data["Jumlah"])),0,",",".")',
  'htmlOptions' => array('style' => 'text-align:center;'),),
  ),
  'pager' => array(
  'cssFile' => Yii::app()->params['backendUrl'] . '/css/style-pager.css',
  'header' => '',
  'firstPageLabel' => 'First',
  'prevPageLabel' => 'Previous',
  'nextPageLabel' => 'Next',
  'lastPageLabel' => 'Last',
  ),
  // 'selectableRows' => 2,
  // 'selectionChanged' => 'userClicks',
  'cssFile' => Yii::app()->params['backendUrl'] . '/css/style-gridview.css',
  ));
 */
/*
 * OMSET
 */
echo '<div class="flat_area grid_16">
    <h2>Omset</h2>
</div>';
echo '
    <link rel="stylesheet" type="text/css" href="http://globalinfinite.com//themes/backend-adminica/views/layouts/css/style-gridview.css" />
<div class="grid-view">
<table width="50%" class="items">
<thead><tr>
<th>Jenis Kartu</th><th>Jumlah Aktivasi</th><th>Harga Aktivasi</th><th>Total Pemasukan (Rp)</th>
</tr></thead>
<tbody>
';

$grand_total = 0;

$total = $result_income[0]['Jumlah'] * 100000;
$grand_total = $grand_total + $total;
echo '<tr class="event"><td>Distributor</td>';
echo '<td align="right">' . $result_income[0]['Jumlah'] . '</td>';
echo '<td align="right">' . number_format('100000', 0, ",", '.') . '</td>';
echo '<td align="right">' . number_format($total, 0, ",", '.') . '</td></tr>';

$total = $result_income[1]['Jumlah'] * 500000;
$grand_total = $grand_total + $total;
echo '<tr class="event"><td>Warehouse</td>';
echo '<td align="right">' . $result_income[1]['Jumlah'] . '</td>';
echo '<td align="right">' . number_format('600000', 0, ",", '.') . '</td>';
echo '<td align="right">' . number_format($total, 0, ",", '.') . '</td></tr>';

echo '<tr class="odd"><td><b>Factory</b></td>';
echo '<td align="right"></td>';
echo '<td align="right"></td>';
echo '<td align="right"></td></tr>';

$total = $income['umroh'][0]['Jumlah'] * 3500000;
$grand_total = $grand_total + $total;
echo '<tr class="event"><td>Umroh</td>';
echo '<td align="right">' . $income['umroh'][0]['Jumlah'] . '</td>';
echo '<td align="right">' . number_format('3500000', 0, ",", '.') . '</td>';
echo '<td align="right">' . number_format($total, 0, ",", '.') . '</td></tr>';

$total = $income['haji'][0]['Jumlah'] * 5000000;
$grand_total = $grand_total + $total;
echo '<tr class="event"><td>Haji</td>';
echo '<td align="right">' . $income['haji'][0]['Jumlah'] . '</td>';
echo '<td align="right">' . number_format('5000000', 0, ",", '.') . '</td>';
echo '<td align="right">' . number_format($total, 0, ",", '.') . '</td></tr>';

$total = $income['produk'][0]['Jumlah'] * 6000000;
$grand_total = $grand_total + $total;
echo '<tr class="event"><td>Produk</td>';
echo '<td align="right">' . $income['produk'][0]['Jumlah'] . '</td>';
echo '<td align="right">' . number_format('6000000', 0, ",", '.') . '</td>';
echo '<td align="right">' . number_format($total, 0, ",", '.') . '</td></tr>';

$total = $income['edukasi'][0]['Jumlah'] * 3250000;
$grand_total = $grand_total + $total;
echo '<tr class="event"><td>Edukasi</td>';
echo '<td align="right">' . $income['edukasi'][0]['Jumlah'] . '</td>';
echo '<td align="right">' . number_format('3250000', 0, ",", '.') . '</td>';
echo '<td align="right">' . number_format($total, 0, ",", '.') . '</td></tr>';

$total = $income['umhj'][0]['Jumlah'] * 5000000;
$grand_total = $grand_total + $total;
echo '<tr class="event"><td>Upgrade umroh haji</td>';
echo '<td align="right">' . $income['umhj'][0]['Jumlah'] . '</td>';
echo '<td align="right">' . number_format('5000000', 0, ",", '.') . '</td>';
echo '<td align="right">' . number_format($total, 0, ",", '.') . '</td></tr>';

echo '<thead><tr><th colspan="3">Grand Total</th><th  align="right">' . number_format($grand_total, 0, ',', '.') . '</th></tr></thead>';

echo '
</tbody>
</table>
</div>
';
/*
 * EOF OMSET
 */

/*
 * Bonus
 */
echo '<div class="flat_area grid_16">
    <h2>Bonus</h2>
</div>';
echo '
<div class="grid-view">
<table width="50%" class="items">
<thead><tr>
<th>Jenis Bonus</th><th>Total Rp</th>
</tr></thead>
<tbody>
';
//echo '<pre>';
//print_r($results);
//echo $results['results_sponsor']['total_sponsor'];
$no = 1;
$grandTotal = 0;
foreach ($results AS $key => $val) {
    $grandTotal+=$val['total_' . $key];
    $class_tr = ($no % 2 == 0) ? 'odd' : 'event';
    echo '<tr class="' . $class_tr . '"><td align="center">Bonus ' . ucfirst(str_replace('_', ' ', $key)) . '</td><td align="right">' . number_format($val['total_' . $key], 0, ',', '.') . '</td></tr>';
    $no++;
}
echo '
<thead>
<tr><th align="center">Grand Total</th><th align="right">' . number_format($grandTotal, 0, ',', '.') . '</th></tr>
</thead>
';

echo '
</tbody>
</table>
</div>
';
/*
 * EOF Bonus
 */
echo '<div class="flat_area grid_16">
    <h2>Ewallet</h2>
</div>';
/*
 * Ewallet
 */

echo '
    <link rel="stylesheet" type="text/css" href="http://globalinfinite.com//themes/backend-adminica/views/layouts/css/style-gridview.css" />
<div class="grid-view">
<table width="50%" class="items">
<thead><tr>
<th>Jenis Ewallet</th><th>Jumlah (Rp)</th>
</tr></thead>
<tbody>
';
$ewallet_total = $ewallet[0]['cash'] + $ewallet[0]['product'] + $ewallet[0]['voucher'] + $ewallet[0]['extra'];
echo '<tr class="event"><td><b>Cash</b></td>';
echo '<td align="right">' . number_format($ewallet[0]['cash']) . '</td></tr>';

echo '<tr class="odd"><td><b>Produk</b></td>';
echo '<td align="right">' . number_format($ewallet[0]['product']) . '</td></tr>';

echo '<tr class="event"><td><b>Voucher</b></td>';
echo '<td align="right">' . number_format($ewallet[0]['voucher']) . '</td></tr>';

echo '<tr class="event"><td><b>Extra</b></td>';
echo '<td align="right">' . number_format($ewallet[0]['extra']) . '</td></tr>';

echo '
<thead>
<tr><th align="center">Grand Total</th><th align="right">' . number_format($ewallet_total, 0, ',', '.') . '</th></tr>
</thead>
';

echo '
</tbody>
</table>
</div>
';
/*
 * EOF ewallet
 */
echo '<div class="flat_area grid_16">
    <h2>Withdrawal Ewallet</h2>
</div>';
/*
 * withdraw
 */
echo '
<div class="grid-view">
<table width="50%" class="items">
<thead><tr>
<th>Jenis Ewallet</th><th>Total Rp</th>
</tr></thead>
<tbody>
';
//echo '<pre>';
//print_r($results);
//echo $results['results_sponsor']['total_sponsor'];
$no = 1;
$grandTotal = 0;
foreach ($withdraw AS $key => $val) {
    $grandTotal+=$val['total'];
    $class_tr = ($no % 2 == 0) ? 'odd' : 'event';
    echo '<tr class="' . $class_tr . '"><td align="center">Ewallet ' . ucfirst(str_replace('_', ' ', $val['ewallet_log_type'])) . '</td><td align="right">' . number_format($val['total'], 0, ',', '.') . '</td></tr>';
    $no++;
}
echo '
<thead>
<tr><th align="center">Grand Total</th><th align="right">' . number_format($grandTotal, 0, ',', '.') . '</th></tr>
</thead>
';

echo '
</tbody>
</table>
</div>
';
/*
 * EOF withdraw
 */
?>

